package com.stormrage.edu.dao.ent.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.ent.EntResDao;
import com.stormrage.entity.ent.EntRes;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
@Repository
public class EntResDaoImpl extends MysBaseDao implements EntResDao {

	private static final Logger LOG = LoggerFactory.getLogger(EntResDaoImpl.class);

	@Override
	public EntRes queryById(Map<String, Object> map) throws StormrageTechException {

		final String query = "SELECT * FROM ent_res WHERE id = :id";

		LOG.debug(" 数据库执行语句为： " + query);
		EntRes entity = queryObject(query, EntRes.class, map);

		return entity;
	}

	@Override
	public List<EntRes> queryList() throws StormrageTechException {

		final String query = "SELECT * FROM ent_res";

		LOG.debug(" 数据库执行语句为： " + query);
		List<EntRes> array = queryList(query, EntRes.class);

		return array;
	}

	@Override
	public List<EntRes> queryListByTypeParent(Map<String, Object> map) throws StormrageTechException {

		final String query = "SELECT * FROM ent_res WHERE res_type = :resType AND parent_id = :parentId";

		LOG.debug(" 数据库执行语句为： " + query);
		List<EntRes> array = queryList(query, EntRes.class, map);

		return array;
	}

	@Override
	public List<EntRes> queryListByAcctId(Map<String, Object> map) throws StormrageTechException {

		final String query = "SELECT a.permission FROM ent_res AS a, ent_acct_res AS b"
				+ " WHERE a.id = b.res_id AND b.acct_id = :acctId";

		LOG.debug(" 数据库执行语句为： " + query);
		List<EntRes> array = queryList(query, EntRes.class, map);

		return array;
	}

}
